Skip to content

Conversation

@OzBob
Copy link
Contributor

@OzBob OzBob commented Jun 3, 2020

method to create directory to prevent IsolatedStorageException
tabs to spaces - only to be consistent...

Summary

Isolated storage exception example, and doc change

Fixes #Issue_Number (if available)

method to create directory to prevent IsolatedStorageException
tabs to spaces - only to be consistent...
@dotnet-bot dotnet-bot added this to the June 2020 milestone Jun 3, 2020
@OzBob OzBob mentioned this pull request Jun 3, 2020
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating this PR @OzBob

I had one question before we merged this.

@Thraka
Copy link
Contributor

Thraka commented Jun 3, 2020

The indentation on this has changed too, making the code file incorrectly indented.

OzBob added 4 commits June 4, 2020 13:51
indenting to 4 spaces
CreateFolders function removed, originally to cater for when the filename has a Directory Separator Char in it.
indenting to 4 spaces
CreateFolders function removed, originally to cater for when the filename has a Directory Separator Char in it.
indenting to 4 spaces
CreateFolders function removed, originally to cater for when the filename has a Directory Separator Char in it.
indenting to 4 spaces
CreateFolders function removed, originally to cater for when the filename has a Directory Separator Char in it.
@IEvangelist IEvangelist modified the milestones: June 2020, July 2020 Jul 6, 2020
@adegeo adegeo closed this Aug 17, 2020
@adegeo adegeo reopened this Aug 17, 2020
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Bill reviewed and comment was addressed. PR was created before new rules related to PRs and code were created.

Comment on lines +28 to +30
isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory");
Console.WriteLine("Created directories.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional? It removes the "InsideDirectory" and then you try to create a file as a directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not actually deleted but moved to 2nd last line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @OzBob Sorry about that, I was on vacation. I just got back. What I mean is that the directory "InsideDirectory" doesn't seem to be created anymore? Unless I'm missing something, which is possible.

I just created a test project and ran the original code. It worked as expected:

dotnet run

Created directories.
Created a new file in the root.
Created a new file in the InsideDirectory.

I then ran the code from this PR and it failed:

dotnet run

System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
 ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\thrak\AppData\Local\IsolatedStorage\5uysulys.woc\5ou1xfgf.iws\Url.2txcxmkov3cbmd5tmqeaz0ccetpw5zem\Url.2txcxmkov3cbmd5tmqeaz0ccetpw5zem\Files\AnotherTopLevelDirectory\NewFile.txt'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   --- End of inner exception stack trace ---
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFile.CreateFile(String path)
   at tempcode.Program.Main() in C:\temp\tempcode\Program.cs:line 18
Created directories.
Created a new file in the root.
Unhandled exception. System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
 ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\thrak\AppData\Local\IsolatedStorage\5uysulys.woc\5ou1xfgf.iws\Url.2txcxmkov3cbmd5tmqeaz0ccetpw5zem\Url.2txcxmkov3cbmd5tmqeaz0ccetpw5zem\Files\AnotherTopLevelDirectory\InsideDirectory\HereIAm.txt'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   --- End of inner exception stack trace ---
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFile.CreateFile(String path)
   at tempcode.Program.Main() in C:\temp\tempcode\Program.cs:line 35

@adegeo adegeo self-requested a review August 17, 2020 18:17
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there may have been an error in one of the commits. Asking collaborator for feedback.

@BillWagner
Copy link
Member

@OzBob This is getting stale. Can you respond to the previous comment?

@BillWagner BillWagner modified the milestones: July 2020, August 2020 Sep 1, 2020
@adegeo
Copy link
Contributor

adegeo commented Sep 29, 2020

@OzBob Going to close this soon as abandoned. Just FYI 😄 Please respond, cheers!

@adegeo adegeo added the needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution] label Sep 29, 2020
@adegeo adegeo self-assigned this Sep 29, 2020
Copy link
Contributor Author

@OzBob OzBob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what error is holding this up?
can you suggest how to resolve?

Comment on lines +28 to +30
isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory");
Console.WriteLine("Created directories.");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not actually deleted but moved to 2nd last line.

@OzBob
Copy link
Contributor Author

OzBob commented Sep 30, 2020

what does 'project missing' mean in https://github.com/dotnet/docs/pull/18769/checks?check_run_id=994903800?
and how do you suggest it be resolved?

Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code doesn't seem to work as submitted. Please see inline comment.

@adegeo
Copy link
Contributor

adegeo commented Oct 12, 2020

what does 'project missing' mean in https://github.com/dotnet/docs/pull/18769/checks?check_run_id=994903800?
and how do you suggest it be resolved?

This error isn't important for the PR and can be ignored. We've moved to a different snippet processing system and this snippet is part of the old system. We're not requiring community members to create projects (required by the new system) when they are doing minor updates to old snippets.

@OzBob
Copy link
Contributor Author

OzBob commented Oct 14, 2020

We're not requiring community members to create projects
https://github.com/dotnet/docs/pull/18769/checks?check_run_id=994903800
still says:
'missing project'

Code doesn't seem to work as submitted. Please see inline comment.
image

I have a try/catch to prove a point, but the 2nd exception in the inline comment can't be replicated.

My last line of code is to write "Created a new file in the root." to the COnsole. There is no code after that. What line of code in your copy of source.cs is causing that exception?

@adegeo
Copy link
Contributor

adegeo commented Nov 2, 2020

Sorry for the delay. This notification slipped through. Try deleting your isolated storage folder to clear it out.

Using the code from your commit: https://github.com/dotnet/docs/blob/bb8865e133e5751407e4eb3ecebf1c4c9e663272/samples/snippets/csharp/VS_Snippets_CLR/conceptual.isolatedstorage/cs/source.cs

I get this error:

C:\code\Work\dotnet\test\a> dotnet run
System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
 ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\thrak\AppData\Local\IsolatedStorage\5uysulys.woc\5ou1xfgf.iws\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Files\AnotherTopLevelDirectory\NewFile.txt'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   --- End of inner exception stack trace ---
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFile.CreateFile(String path)
   at a.Program.Main(String[] args) in C:\code\Work\dotnet\test\a\Program.cs:line 18
Created directories.
Created a new file in the root.
Unhandled exception. System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
 ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\thrak\AppData\Local\IsolatedStorage\5uysulys.woc\5ou1xfgf.iws\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Files\AnotherTopLevelDirectory\InsideDirectory\HereIAm.txt'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   --- End of inner exception stack trace ---
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFile.CreateFile(String path)
   at a.Program.Main(String[] args) in C:\code\Work\dotnet\test\a\Program.cs:line 35

If I run it a second time, I get this error:

C:\code\Work\dotnet\test\a> dotnet run
Unhandled exception. System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
 ---> System.IO.IOException: The process cannot access the file 'C:\Users\thrak\AppData\Local\IsolatedStorage\5uysulys.woc\5ou1xfgf.iws\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Url.3xes0z4spj2hngysuwp1t4k0om5g1pbk\Files\AnotherTopLevelDirectory\NewFile.txt' because it is being used by another process.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   --- End of inner exception stack trace ---
   at System.IO.IsolatedStorage.IsolatedStorageFileStream.InitializeFileStream(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFile.CreateFile(String path)
   at a.Program.Main(String[] args) in C:\code\Work\dotnet\test\a\Program.cs:line 27

Here is the code I used.

using System;
using System.IO;
using System.IO.IsolatedStorage;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
            {
                isoStore.CreateDirectory("TopLevelDirectory");
                isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");
                var isofilename = "AnotherTopLevelDirectory/NewFile.txt";
                try
                {
                    isoStore.CreateFile(isofilename);
                }
                catch (IsolatedStorageException iex)
                {
                    Console.WriteLine(iex.ToString());
                }

                var path = Path.GetDirectoryName(isofilename);
                isoStore.CreateDirectory(path);//Creating "AnotherTopLevelDirectory";
                isoStore.CreateFile(isofilename);//Creating "AnotherTopLevelDirectory/NewFile.txt";

                isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory");
                Console.WriteLine("Created directories.");

                isoStore.CreateFile("InTheRoot.txt");
                Console.WriteLine("Created a new file in the root.");

                isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
                Console.WriteLine("Created a new file in the InsideDirectory.");
            }
        }
    }
}

@OzBob
Copy link
Contributor Author

OzBob commented Nov 3, 2020

investigating ...

@adegeo
Copy link
Contributor

adegeo commented Feb 2, 2021

Closing this as it's gone stale. Feel free to reopen.

@adegeo adegeo closed this Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants